<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Product;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class ProductController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Product(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('title');
            $grid->column('image');
            $grid->column('advance');
            $grid->column('duration');
            $grid->column('money');
            $grid->column('introduce');
            $grid->column('character');
            $grid->column('value');
            $grid->column('prize')->image();
            $grid->column('help');
            $grid->column('questions')->image();
            $grid->column('sort', '排序');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->export();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
            $grid->disableViewButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Product(), function (Show $show) {
            $show->field('id');
            $show->field('title');
            $show->field('image');
            $show->field('advance');
            $show->field('duration');
            $show->field('money');
            $show->field('introduce');
            $show->field('character');
            $show->field('value');
            $show->field('prize');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Product(), function (Form $form) {
            $form->display('id');
            $form->text('title')->required();
            $form->image('image')->uniqueName()->autoUpload()->required();
            $form->text('advance');
            $form->text('duration');
            $form->text('money');
            $form->editor('introduce');
            $form->editor('character');
            $form->editor('value');
            $form->image('prize')->uniqueName()->autoUpload()->required();
            $form->image('questions')->uniqueName()->autoUpload()->required();
            $form->editor('help');
            $form->text('sort', '排序')->default(100000);

            $form->display('created_at');
            $form->display('updated_at');

            $form->disableViewButton();
            $form->disableViewCheck();
        });
    }
}
